package com.inch.web.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.inch.web.serializer.SalarySerializer;

import java.util.Arrays;
import java.util.Date;

public class User {

    //set the showing key in json of this field eg: in json it will shows { "id2"="123"} instead of {"id"="123"}
    //default is the same as field name
//    @JsonProperty("id2")
    private int id;
    private String name;
    //ignore field when transfer to json
    @JsonIgnore
    private Boolean gender;
    //set the format of date when transfer to a json
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    private Date birth;
    //set field only transfer to json when field not null
//    @JsonInclude(JsonInclude.Include.NON_NULL)
    //not empty  eg: when hobbies = new String[] {}; it will not include
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String[] hobbies;
    //using self defined method to deal with field
    @JsonSerialize(using = SalarySerializer.class)
    private Double salary;


    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", gender=" + gender +
                ", birth=" + birth +
                ", hobbies=" + Arrays.toString(hobbies) +
                '}';
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public String[] getHobbies() {
        return hobbies;
    }

    public void setHobbies(String[] hobbies) {
        this.hobbies = hobbies;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getGender() {
        return gender;
    }

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }
}
